<template>
    <view class="container">
        <!--header-->
        <view class="tui-header-box" :style="{ height: height + 'px', background: 'rgba(255,255,255,' + opcity + ')' }">
            <view class="tui-header" :style="{ paddingTop: top + 'px', opacity: opcity }">商品详情</view>
            <view class="tui-header-icon" :style="{ marginTop: top + 'px' }">
                <view class="tui-icon-box" :style="{ backgroundColor: 'rgba(0, 0, 0,' + iconOpcity + ')' }" @tap="back">
                    <tui-icon name="arrowleft" :size="30" :color="opcity >= 1 ? '#000' : '#fff'"></tui-icon>
                </view>
                <!-- 
                <view class="tui-icon-box tui-icon-ml" :style="{backgroundColor: 'rgba(0, 0, 0,' + iconOpcity + ')'}"
                    @tap.stop="openMenu">
                    <tui-icon name="more-fill" :size="20" :color="opcity >= 1 ? '#000' : '#fff'"></tui-icon>
                    <tui-badge type="red" :scaleRatio="0.8" absolute top="0" right="-4rpx">5</tui-badge>
                </view> -->

            </view>
        </view>
        <!--header-->

        <!--banner-->
        <view class="tui-banner-swiper">
            <swiper :autoplay="true" :interval="5000" :duration="150" :circular="true"
                :style="{ height: scrollH + 'px' }" @change="bannerChange">
                <block v-for="(item, index) in banner" :key="index">
                    <swiper-item :data-index="index" @tap.stop="previewImage">
                        <image :src="item" class="tui-slide-image" :style="{ height: scrollH + 'px' }"></image>
                    </swiper-item>
                </block>
            </swiper>
            <!-- <view class="tui-video__box" @tap.stop="play">
                <image src="https://www.thorui.cn/images/mall/img_video_3x.png" mode="widthFix"></image>
                <view>00′30″</view>
            </view> -->
            <view class="tui-banner-tag">
                <tui-tag padding="12rpx 18rpx" type="translucent" shape="circleLeft" :scaleMultiple="0.82"
                    originRight>{{ bannerIndex + 1 }}/{{ banner.length }}</tui-tag>
            </view>
        </view>

        <!--banner-->

        <view class="tui-pro-detail">
            <!-- 商品信息卡片 -->
            <view class="tui-product-card">
                <!-- 价格区域 -->
                <view class="tui-price-section">
                    <view class="tui-price-main">
                        <view class="tui-current-price">
                            <text class="tui-price-symbol">¥</text>
                            <text class="tui-price">{{fen2yuan((selectedSku && selectedSku.price) || (proDetail && proDetail.price) || 0)}}</text>
                        </view>
                        <view class="tui-original-price" v-if="(selectedSku && selectedSku.marketPrice) || (proDetail && proDetail.marketPrice)">
                            <text class="tui-price-symbol">¥</text>
                            <text class="tui-original-price-text">{{fen2yuan((selectedSku && selectedSku.marketPrice) || (proDetail && proDetail.marketPrice) || 0)}}</text>
                        </view>
                    </view>
                    <view class="tui-price-actions">
                        <view class="tui-collection-btn" @tap="collecting">
                            <tui-icon :name="collected ? 'like-fill' : 'like'" :color="collected ? '#ff201f' : '#666'"
                                :size="20"></tui-icon>
                            <text class="tui-collection-text" :class="{'tui-collected':collected}">收藏</text>
                        </view>
                        <button open-type="share" class="tui-share-btn" @tap="onShare">
                            <tui-icon name="partake" color="#666" :size="20"></tui-icon>
                            <text class="tui-share-text">分享</text>
                        </button>
                    </view>
                </view>

                <!-- 商品标题 -->
                <view class="tui-title-section">
                    <view class="tui-product-title">{{proDetail.name}}</view>
                    <view class="tui-product-subtitle" v-if="proDetail.introduction && proDetail.introduction !== proDetail.name">
                        {{proDetail.introduction}}
                    </view>
                </view>

                <!-- 商品标签 -->
                <view class="tui-tags-section">
                    <view class="tui-tag">热销</view>
                    <view class="tui-tag">包邮</view>
                    <view class="tui-tag">正品保证</view>
                    <view class="tui-tag">7天无理由退货</view>
                </view>

                <!-- 销量信息 -->
                <view class="tui-sales-info">
                    <view class="tui-sales-item">
                        <text class="tui-sales-label">销量：</text>
                        <text class="tui-sales-value">{{proDetail.salesCount || 0}}件</text>
                    </view>
                    <view class="tui-sales-item">
                        <text class="tui-sales-label">库存：</text>
                        <text class="tui-sales-value">{{(selectedSku && selectedSku.stock) || (proDetail && proDetail.stock) || 0}}件</text>
                    </view>
                    <view class="tui-sales-item" v-if="selectedSku && selectedSku.weight && selectedSku.weight > 0">
                        <text class="tui-sales-label">重量：</text>
                        <text class="tui-sales-value">{{selectedSku.weight}}kg</text>
                    </view>
                </view>
            </view>



            <!-- 规格选择卡片 -->
            <view class="tui-spec-card">
                <view class="tui-spec-header" @tap="showPopup">
                    <view class="tui-spec-title">
                        <text class="tui-spec-label">已选</text>
                        <view class="tui-spec-content">
                            <text class="tui-spec-text">{{ selectedSpecText || '请选择规格' }}</text>
                        </view>
                    </view>
                    <view class="tui-spec-arrow">
                        <tui-icon name="more-fill" :size="20" color="#999"></tui-icon>
                    </view>
                </view>
                
                <!-- 服务保障 -->
                <view class="tui-service-guarantee">
                    <view class="tui-guarantee-item">
                        <tui-icon name="circle-selected" :size="14" color="#52c41a"></tui-icon>
                        <text class="tui-guarantee-text">正品保证</text>
                    </view>
                    <view class="tui-guarantee-item">
                        <tui-icon name="circle-selected" :size="14" color="#52c41a"></tui-icon>
                        <text class="tui-guarantee-text">7天无理由退货</text>
                    </view>
                    <view class="tui-guarantee-item">
                        <tui-icon name="circle-selected" :size="14" color="#52c41a"></tui-icon>
                        <text class="tui-guarantee-text">闪电发货</text>
                    </view>
                    <view class="tui-guarantee-item">
                        <tui-icon name="circle-selected" :size="14" color="#52c41a"></tui-icon>
                        <text class="tui-guarantee-text">极速退款</text>
                    </view>
                </view>
            </view>

            <!-- <view class="tui-cmt-box tui-mtop tui-radius-all">
                <view class="tui-list-cell tui-last tui-between">
                    <view class="tui-bold tui-cell-title">评价</view>
                    <view class="tui-flex-center" @tap="evaluate">
                        <text class="tui-cmt-all">查看全部</text>
                        <tui-icon name="more-fill" :size="20" color="#ff201f"></tui-icon>
                    </view>
                </view>

                <view class="tui-cmt-content tui-padding">
                    <view class="tui-cmt-user">
                        <image src="/static/images/news/avatar_2.jpg" class="tui-acatar"></image>
                        <view>z***9</view>
                    </view>
                    <view class="tui-cmt">物流很快，很适合我的风格❤</view>
                    <view class="tui-attr">颜色：叠层钛钢流苏耳环（A74）</view>
                </view>

                <view class="tui-cmt-btn">
                    <tui-button width="240rpx" height="64rpx" :size="24" type="black" plain shape="circle"
                        @click="evaluate">查看全部评价</tui-button>
                </view>
            </view> -->

            <!-- 商品详情标题 -->
            <view class="tui-detail-header">
                <view class="tui-detail-title">
                    <view class="tui-detail-icon">
                        <tui-icon name="list" color="#ff6b35" :size="20"></tui-icon>
                    </view>
                    <text class="tui-detail-text">商品详情</text>
                </view>
                <view class="tui-detail-line"></view>
            </view>
            
            <!-- 商品详情内容 -->
            <view class="tui-product-detail-content">
                <view class="tui-detail-wrapper" v-html="proDetail.description"></view>
            </view>
            
            <!-- 底部提示 -->
            <view class="tui-detail-footer">
                <view class="tui-footer-content">
                    <tui-icon name="check" color="#52c41a" :size="16"></tui-icon>
                    <text class="tui-footer-text">已浏览完所有商品详情</text>
                </view>
            </view>
            <view class="tui-safearea-bottom"></view>
        </view>

        <!--底部操作栏-->
        <view class="tui-bottom-bar">
            <view class="tui-bottom-actions">
                <view class="tui-action-item" @tap="shop">
                    <tui-icon name="shop" :size="24" color="#666"></tui-icon>
                    <text class="tui-action-text">首页</text>
                </view>
                <view class="tui-action-item" @click="toShopcart">
                    <view class="tui-cart-icon">
                        <tui-icon name="cart" :size="24" color="#666"></tui-icon>
                        <tui-badge type="red" absolute :scaleRatio="0.8" right="-8rpx" top="-8rpx"
                            v-if="cartCount > 0">{{ cartCount > 99 ? '99+' : cartCount }}</tui-badge>
                    </view>
                    <text class="tui-action-text">购物车</text>
                </view>
                <view class="tui-action-item" @tap="collecting">
                    <tui-icon :name="collected ? 'like-fill' : 'like'" :color="collected ? '#ff201f' : '#666'" :size="24"></tui-icon>
                    <text class="tui-action-text" :class="{'tui-collected':collected}">收藏</text>
                </view>
                <view class="tui-action-item" @tap="contactService">
                    <tui-icon name="kefu" :size="24" color="#666"></tui-icon>
                    <text class="tui-action-text">客服</text>
                </view>
            </view>
            <view class="tui-bottom-buttons">
                <view class="tui-btn-container">
                    <tui-button :disabled="!canOperate" height="72rpx" :size="28" type="danger" shape="circle"
                        @click="showPopup" class="tui-cart-btn">加入购物车</tui-button>
                </view>
                <view class="tui-btn-container">
                    <tui-button :disabled="!canOperate" height="72rpx" :size="28" type="warning" shape="circle"
                        @click="submit" class="tui-buy-btn">立即购买</tui-button>
                </view>
            </view>
        </view>

        <!--底部操作栏-->

        <!--顶部下拉菜单-->
        <tui-top-dropdown backgroundColor="rgba(76, 76, 76, 0.95)" :show="menuShow" :height="0" @close="closeMenu">
            <view class="tui-menu-box tui-padding tui-ptop">
                <view class="tui-menu-header" :style="{ paddingTop: top + 'px' }">功能直达</view>
                <view class="tui-menu-itembox">
                    <block v-for="(item, index) in topMenu" :key="index">
                        <view class="tui-menu-item" hover-class="tui-opcity" :hover-stay-time="150"
                            @tap="btnTopMenu(index)">
                            <view class="tui-badge-box">
                                <tui-icon :name="item.icon" color="#fff" :size="item.size"></tui-icon>
                                <tui-badge type="red" :scaleRatio="0.8" absolute right="-8rpx" v-if="item.badge">{{
                                    item.badge }}</tui-badge>
                            </view>
                            <view class="tui-menu-text">{{ item.text }}</view>
                        </view>
                    </block>
                </view>
                <view class="tui-icon-up_box">
                    <tui-icon name="up" color="#fff" :size="26" @click="closeMenu"></tui-icon>
                </view>
            </view>
        </tui-top-dropdown>
        <!---顶部下拉菜单-->

        <!--底部选择层-->
        <tui-bottom-popup :zIndex="99999" :show="popupShow" @close="hidePopup">
            <view class="tui-popup-box">
                <view class="tui-product-box tui-padding">
                    <image :src="(selectedSku && selectedSku.picUrl) || (proDetail && proDetail.picUrl) || ''" class="tui-popup-img"></image>
                    <view class="tui-popup-price">
                        <view class="tui-popup-price-main">
                            <view class="tui-amount tui-bold">￥{{ fen2yuan((selectedSku && selectedSku.price) || (proDetail && proDetail.price) || 0) }}</view>
                            <view class="tui-original-amount" v-if="(selectedSku && selectedSku.marketPrice) || (proDetail && proDetail.marketPrice)">
                                ￥{{ fen2yuan((selectedSku && selectedSku.marketPrice) || (proDetail && proDetail.marketPrice) || 0) }}
                            </view>
                        </view>
                        <view class="tui-number">编号:{{ (selectedSku && selectedSku.id) || (proDetail && proDetail.id) || '' }}</view>
                        <view class="tui-stock">库存: {{ (selectedSku && selectedSku.stock) || (proDetail && proDetail.stock) || 0 }}</view>
                    </view>
                </view>
                <scroll-view scroll-y class="tui-popup-scroll">
                    <view class="tui-scrollview-box">
                        <!-- 动态生成规格属性 -->
                        <view v-for="(spec, index) in specs" :key="index">
                            <view class="tui-bold tui-attr-title">{{ spec.propertyName }}</view>
                            <view class="tui-attr-box">
                                <view v-for="value in spec.values" :key="value.valueId" class="tui-attr-item"
                                    :class="{ 'tui-attr-active': isSpecSelected(spec.propertyId, value.valueId) }"
                                    @click="selectSpec(spec.propertyId, value.valueId)">
                                    {{ value.valueName }}
                                </view>
                            </view>
                        </view>
                        <!-- 数量选择 -->
                        <view class="tui-number-box tui-bold tui-attr-title">
                            <view class="tui-attr-title">数量</view>
                            <tui-numberbox :max="(selectedSku && selectedSku.stock) || (proDetail && proDetail.stock) || 99" :min="1" :value="quantity"
                                @change="onQuantityChange"></tui-numberbox>
                        </view>
                    </view>
                </scroll-view>
                <view class="tui-operation tui-operation-right tui-right-flex tui-popup-btn">
                    <view class="tui-flex-1">
                        <tui-button height="72rpx" :size="28" type="danger" shape="circle"
                            @click="addToCartFromPopup">
                            加入购物车
                        </tui-button>
                    </view>
                    <view class="tui-flex-1">
                        <tui-button height="72rpx" :size="28" type="warning" shape="circle"
                            @click="buyNowFromPopup">
                            立即购买
                        </tui-button>
                    </view>
                </view>
                <view class="tui-right">
                    <tui-icon name="close-fill" color="#999" :size="20" @click="hidePopup"></tui-icon>
                </view>
            </view>
        </tui-bottom-popup>
        <!--底部选择层-->
    </view>
</template>

<script>

    export default {
        // 页面级分享配置
        onShareAppMessage() {
            return {
                title: (this.proDetail && this.proDetail.name) || '商品详情',  // 分享的标题
                path: `/subPackage2/productDetail/productDetail?id=${this.id}`,  // 分享的路径（可以加查询参数）
                imageUrl: (this.proDetail && this.proDetail.picUrl) || '',  // 分享的图片
            };
        },
        data() {
            return {
                proDetail: null,
                height: 64, //header高度
                top: 26, //标题图标距离顶部距离
                scrollH: 0, //滚动总高度
                opcity: 0,
                iconOpcity: 0.5,
                banner: [

                ],
                bannerIndex: 0,
                topMenu: [{
                    icon: 'message',
                    text: '消息',
                    size: 26,
                    badge: 3
                },
                {
                    icon: 'home',
                    text: '首页',
                    size: 23,
                    badge: 0
                },
                {
                    icon: 'people',
                    text: '我的',
                    size: 26,
                    badge: 0
                },
                {
                    icon: 'cart',
                    text: '购物车',
                    size: 23,
                    badge: 2
                },
                {
                    icon: 'kefu',
                    text: '客服小蜜',
                    size: 26,
                    badge: 0
                },
                {
                    icon: 'feedback',
                    text: '我要反馈',
                    size: 23,
                    badge: 0
                },
                {
                    icon: 'share',
                    text: '分享',
                    size: 26,
                    badge: 0
                }
                ],
                menuShow: false,
                proDetail: null,
                proDetail: null,
                popupShow: false,
                specs: [], // 存储规格属性
                selectedSpec: {}, // 当前选中规格值 { propertyId: valueId }
                selectedSku: {}, // 当前选中的SKU
                skus: [], // SKU数据
                selectedSpecText: "", // 拼接的规格文本
                quantity: 1, // 当前选中的数量
                value: 1,
                collected: false,
                id: 0,
                selectedSkuId: null,
                shopCartList: [],
                cartCount: 0 // 购物车商品总数量
            };
        },
        onLoad: function (options) {
            this.id = options.id

            let obj = {};
            // #ifdef MP-WEIXIN
            obj = wx.getMenuButtonBoundingClientRect();
            // #endif
            // #ifdef MP-BAIDU
            obj = swan.getMenuButtonBoundingClientRect();
            // #endif
            // #ifdef MP-ALIPAY
            my.hideAddToDesktopMenu();
            // #endif

            setTimeout(() => {
                uni.getSystemInfo({
                    success: res => {
                        this.width = obj.left || res.windowWidth;
                        this.height = obj.top ? obj.top + obj.height + 8 : res.statusBarHeight + 44;
                        this.top = obj.top ? obj.top + (obj.height - 32) / 2 : res.statusBarHeight + 6;
                        this.scrollH = res.windowWidth;
                    }
                });
            },0);
        },
        mounted() {
            this.loadProDetail()
            this.loadShopCartList()
            this.loadCartCount()
            // 监听购物车变化事件
            uni.$on('refreshCart', this.loadCartCount);
        },
        onShow() {
            // 调用接口重新获取收藏状态
            this.refreshFavoriteStatus()
            // 每次页面显示时刷新购物车数量
            this.loadCartCount()
        },
        beforeDestroy() {
            // 移除事件监听
            uni.$off('refreshCart', this.loadCartCount);
        },
        computed: {
            canOperate() {
                // 判断是否可以操作（始终允许操作，未选择规格时会弹出选择弹窗）
                if (!this.selectedSku) {
                    return true; // 没有选择SKU时也允许操作，会弹出规格选择弹窗
                }
                const skuStock = this.selectedSku.stock || 0;
                return skuStock > 0;
            },
        },
        methods: {
            // 分转元函数，参考 yudao-mall
            fen2yuan(price) {
                return (Number(price) / 100).toFixed(2);
            },
            refreshFavoriteStatus() {
                this.$api.req(`/product/favorite/exits?spuId=${this.id}`,{},"get","JSON",false).then((res) => {
                    if (res.code === 0) {
                        this.collected = res.data;
                    }
                    // this.collected = false;
                });
            },
            // 加载购物车列表
            loadShopCartList() {
                this.$api.req("/trade/cart/list",{},"get","JSON",false).then((res) => {
                    if (res.code === 0) {
                        this.shopCartList = res.data.validList
                    }
                });
            },
            // 获取购物车商品数量
            loadCartCount() {
                this.$api.req("/trade/cart/list",{},"get","JSON",false).then((res) => {
                    if (res.code === 0) {
                        // 计算购物车有效商品总数量
                        this.cartCount = (res.data.validList || []).reduce((sum, item) => sum + item.count, 0);
                    }
                }).catch((err) => {
                    console.error('获取购物车数量失败:', err);
                    this.cartCount = 0;
                });
            },
            toShopcart() {
                this.f.nav('/subPackage2/shopcart/shopcart')
            },
            loadProDetail() {
                // 加载商品详情
                this.$api
                    .req(
                        `/product/spu/get-detail`,
                        { id: this.id },
                        "get",
                        "JSON",
                        false
                    )
                    .then((res) => {
                        if (res.code === 0) {
                            const data = res.data;
                            // 处理轮播图数据
                            this.banner = data.sliderPicUrls || [data.picUrl];
                            
                            // 处理商品详情数据
                            this.proDetail = {
                                id: data.id,
                                name: data.name,
                                introduction: data.introduction,
                                description: data.description,
                                categoryId: data.categoryId,
                                picUrl: data.picUrl,
                                sliderPicUrls: data.sliderPicUrls,
                                specType: data.specType,
                                price: data.price,
                                marketPrice: data.marketPrice,
                                stock: data.stock,
                                salesCount: data.salesCount,
                                deliveryTypes: data.deliveryTypes || []
                            };
                            
                            // 处理SKU数据
                            this.skus = data.skus || [];
                            this.initSpecs();
                            
                            // 不自动选择SKU，让用户主动选择
                            // 即使有SKU，也需要用户主动点击选择
                            this.selectedSku = null;
                        } else {
                            uni.showToast({
                                title: res.msg || '加载商品详情失败',
                                icon: 'none'
                            });
                        }
                    })
                    .catch((error) => {
                        console.error('加载商品详情失败:', error);
                        uni.showToast({
                            title: '网络异常，请稍后重试',
                            icon: 'none'
                        });
                    });
            },
            initSpecs() {
                // 初始化规格属性
                const specMap = {};
                this.skus.forEach((sku) => {
                    sku.properties.forEach((prop) => {
                        if (!specMap[prop.propertyId]) {
                            specMap[prop.propertyId] = {
                                propertyId: prop.propertyId,
                                propertyName: prop.propertyName,
                                values: [],
                            };
                        }
                        if (
                            !specMap[prop.propertyId].values.some(
                                (v) => v.valueId === prop.valueId
                            )
                        ) {
                            specMap[prop.propertyId].values.push({
                                valueId: prop.valueId,
                                valueName: prop.valueName,
                            });
                        }
                    });
                });
                this.specs = Object.values(specMap);
                this.selectedSpec = {};
                
                // 不自动选择SKU，让用户主动选择
                // 即使只有一个SKU，也需要用户主动点击选择
                this.selectedSku = null;
            },
            isSpecSelected(propertyId,valueId) {
                // 判断规格是否选中
                return this.selectedSpec[propertyId] === valueId;
            },
            updateSelectedSpecText() {
                // 更新选中规格的文本显示
                if (this.selectedSku && this.selectedSku.properties) {
                    this.selectedSpecText = this.selectedSku.properties
                        .map(prop => `${prop.propertyName}: ${prop.valueName}`)
                        .join(' ');
                } else {
                    this.selectedSpecText = '请选择规格';
                }
            },
            selectSpec(propertyId,valueId) {
                // 保存选中规格 { propertyId: valueId }
                this.$set(this.selectedSpec,propertyId,valueId);

                // 调用更新选中的SKU
                this.updateSelectedSku();
            },
            updateSelectedSku() {
                // 更新选中的 SKU，通过匹配 skus 数组中的 properties
                const selectedProperties = Object.entries(this.selectedSpec).map(
                    ([propertyId,valueId]) => ({
                        propertyId: Number(propertyId),
                        valueId: Number(valueId)
                    })
                );

                // 查找匹配的 SKU
                const matchedSku = this.skus.find((sku) =>
                    selectedProperties.every((selectedProp) =>
                        sku.properties.some(
                            (skuProp) =>
                                skuProp.propertyId === selectedProp.propertyId &&
                                skuProp.valueId === selectedProp.valueId
                        )
                    )
                );

                // 如果找到匹配的 SKU，保存其 ID 和其他数据
                if (matchedSku) {
                    this.selectedSku = matchedSku; // 保存匹配到的 SKU
                    this.selectedSkuId = matchedSku.id; // 保存 SKU 的 ID
                    this.updateSelectedSpecText(); // 更新规格文本显示
                    console.log('选中的 SKU ID:',this.selectedSkuId);
                } else {
                    // 如果没有匹配到 SKU，重置
                    this.selectedSku = {};
                    this.selectedSkuId = null;
                    console.log('没有匹配到对应的 SKU');
                }
            },
            updateSelectedSpecText() {
                // 如果没有选择SKU，显示提示
                if (!this.selectedSku) {
                    this.selectedSpecText = "请选择规格";
                    return;
                }
                
                // 拼接选中规格文本，包括数量
                const selectedText = this.specs
                    .map((spec) => {
                        const valueId = this.selectedSpec[spec.propertyId];
                        const value = spec.values.find((v) => v.valueId === valueId);
                        return value ? value.valueName : null;
                    })
                    .filter((text) => text) // 移除空值
                    .join(", ");
                this.selectedSpecText = selectedText
                    ? `${selectedText}, ${this.quantity}个`
                    : "请选择规格";
            },
            onQuantityChange(e) {
                // console.log(value);

                // 更新数量
                this.quantity = e.value;
                // this.updateSelectedSpecText();
            },
            addToCartFromPopup() {
                // 弹窗中的加入购物车
                if (!this.selectedSku) {
                    return uni.showToast({
                        title: "请先选择商品规格",
                        icon: "none",
                    });
                }
                const skuId = this.selectedSku.id;
                if (!skuId) {
                    return uni.showToast({
                        title: "请选择商品规格",
                        icon: "none",
                    });
                }
                this.$api.req(`/trade/cart/add`,{ skuId: skuId, count: this.quantity },'POST',"JSON",false).then(res => {
                    if (res.code === 0) {
                        this.f.msg('已添加购物车')
                        this.loadShopCartList()
                        this.hidePopup(); // 关闭弹窗
                        // 触发购物车数量更新事件
                        uni.$emit('refreshCart');
                    }
                })
            },
            buyNowFromPopup() {
                // 弹窗中的立即购买
                if (!this.selectedSku) {
                    return uni.showToast({
                        title: "请先选择商品规格",
                        icon: "none",
                    });
                }
                const skuId = this.selectedSku.id;
                if (!skuId) {
                    return uni.showToast({
                        title: "请选择商品规格",
                        icon: "none",
                    });
                }
                var items = [
                    {
                        skuId: skuId,
                        count: this.quantity,
                    },
                ]
                if (items.length > 0 && items[0].count > 0) {
                    // 传递商品信息和发货方式
                    const orderData = {
                        items: items,
                        deliveryTypes: this.proDetail.deliveryTypes || []
                    }
                    this.hidePopup(); // 关闭弹窗
                    this.f.nav(`/subPackage2/submitOrder/submitOrder?orderData=${JSON.stringify(orderData)}`)
                } else {
                    this.hidePopup(); // 关闭弹窗
                    this.f.nav(`/subPackage2/submitOrder/submitOrder`)
                }
                console.log("立即购买",{
                    skuId: this.selectedSku.id,
                    quantity: this.quantity,
                    selectedSpec: this.selectedSpec,
                });
            },
            addToCart() {
                // 加入购物车
                if (!this.selectedSku) {
                    // 没有选择规格时，弹出规格选择弹窗
                    this.popupShow = true;
                    return;
                }
                const skuId = this.selectedSku.id;
                if (!skuId) {
                    // 没有选择规格时，弹出规格选择弹窗
                    this.popupShow = true;
                    return;
                }
                this.$api.req(`/trade/cart/add`,{ skuId: skuId, count: this.quantity },'POST',"JSON",false).then(res => {
                    if (res.code === 0) {
                        this.f.msg('已添加购物车')
                        this.loadShopCartList()
                        // 触发购物车数量更新事件
                        uni.$emit('refreshCart');
                    }
                });
                // /trade/cart/add
                // console.log("加入购物车",{
                //     skuId: this.selectedSku.id,
                //     quantity: this.quantity,
                //     selectedSpec: this.selectedSpec,
                // });
            },
            buyNow() {
                // 立即购买
                if (!this.selectedSku) {
                    // 没有选择规格时，弹出规格选择弹窗
                    this.popupShow = true;
                    return;
                }
                const skuId = this.selectedSku.id;
                if (!skuId) {
                    // 没有选择规格时，弹出规格选择弹窗
                    this.popupShow = true;
                    return;
                }
                var items = [
                    {
                        skuId: skuId,
                        count: this.quantity,
                    },
                ]
                if (items.length > 0 && items[0].count > 0) {
                    // 传递商品信息和发货方式
                    const orderData = {
                        items: items,
                        deliveryTypes: this.proDetail.deliveryTypes || []
                    }
                    this.f.nav(`/subPackage2/submitOrder/submitOrder?orderData=${JSON.stringify(orderData)}`)
                } else {
                    this.f.nav(`/subPackage2/submitOrder/submitOrder`)
                }

                console.log("立即购买",{
                    skuId: this.selectedSku.id,
                    quantity: this.quantity,
                    selectedSpec: this.selectedSpec,
                });
            },
            hidePopup() {
                this.popupShow = false;
            },
            bannerChange: function (e) {
                this.bannerIndex = e.detail.current;
            },
            previewImage: function (e) {
                let index = e.currentTarget.dataset.index;
                uni.previewImage({
                    current: this.banner[index],
                    urls: this.banner
                });
            },
            back: function () {
                uni.navigateBack();
            },
            openMenu: function () {
                this.menuShow = true;
            },
            closeMenu: function () {
                this.menuShow = false;
            },
            showPopup() {
                this.popupShow = true;
                return;
                if (this.skus.length > 0 && Object.keys(this.selectedSpec).length !== this.specs.length) {
                    // 有规格且未选择完整，弹出选择规格弹窗
                    this.popupShow = true;
                    // uni.showToast({
                    //     title: '请选择完整规格',
                    //     icon: 'none',
                    // });
                    return;
                }

                // 如果商品无规格或规格已选择完整，执行加入购物车逻辑
                // console.log("加入购物车",{
                //     skuId: this.selectedSku.id || this.proDetail.id,
                //     quantity: this.quantity,
                // });
            },
            submit() {
                this.popupShow = true;
                // if (this.skus.length > 0 && Object.keys(this.selectedSpec).length !== this.specs.length) {
                //     // 有规格且未选择完整，弹出选择规格弹窗
                //     this.popupShow = true;
                //     // uni.showToast({
                //     //     title: '请选择完整规格',
                //     //     icon: 'none',
                //     // });
                //     return;
                // }

                // 如果商品无规格或规格已选择完整，执行立即购买逻辑
                // console.log("立即购买",{
                //     skuId: this.selectedSku.id || this.proDetail.id,
                //     quantity: this.quantity,
                // });

                // 跳转到提交订单页面
                // uni.navigateTo({
                //     url: '../submitOrder/submitOrder',
                // });
            },
            hidePopup: function () {
                this.popupShow = false;
            },
            change: function (e) {
                this.value = e.value;
            },
            collecting() {
                // 添加一个变量来控制收藏按钮点击时的加载状态（比如透明度变化等交互效果），初始设为 0.5 表示半透明加载态
                this.isCollectingOpactiy = 0.5;
                if (this.collected) {
                    // 如果当前是已收藏状态，调用取消收藏接口
                    this.$api.req('/product/favorite/delete',{ spuId: this.id },'DELETE','JSON',false).then((res) => {
                        if (res.code === 0) {
                            // 取消收藏成功，更新收藏状态为未收藏
                            this.collected = false;
                            this.f.msg('取消收藏操作成功');
                            // 刷新收藏状态显示，确保页面展示准确
                            this.refreshFavoriteStatus();
                        } else {
                            // 取消收藏失败，给出提示
                            this.f.msg('取消收藏操作失败，请稍后再试');
                        }
                        // 无论成功失败，操作完成后恢复按钮正常状态（透明度设为 1）
                        this.isCollectingOpactiy = 1;
                    }).catch((err) => {
                        // 捕获取消收藏接口调用出现的异常，如网络问题等
                        console.error('取消收藏接口调用出错：',err);
                        this.f.msg('网络异常，取消收藏操作未能完成，请检查网络');
                        // 出现异常也恢复按钮正常状态
                        this.isCollectingOpactiy = 1;
                    });
                } else {
                    // 如果当前是未收藏状态，调用创建收藏接口
                    this.$api.req('/product/favorite/create',{ spuId: this.id },'POST','JSON',false).then((res) => {
                        if (res.code === 0) {
                            // 创建收藏成功，更新收藏状态为已收藏
                            this.collected = true;
                            this.f.msg('收藏操作成功');
                            // 同样刷新收藏状态显示
                            this.refreshFavoriteStatus();
                        } else {
                            // 创建收藏失败，给出提示
                            this.f.msg('收藏操作失败，请稍后再试');
                        }
                        // 操作完成后恢复按钮正常状态
                        this.isCollectingOpactiy = 1;
                    }).catch((err) => {
                        // 捕获创建收藏接口调用出现的异常
                        console.error('创建收藏接口调用出错：',err);
                        this.f.msg('网络异常，收藏操作未能完成，请检查网络');
                        this.isCollectingOpactiy = 1;
                    });
                }
            },
            evaluate() {
                this.f.nav('../goodsEvaluate/goodsEvaluate')
            },
            common: function () {
                this.tui.toast('功能开发中~');
            },
            btnTopMenu(index) {
                this.closeMenu()
                if (index == 4) {
                    uni.makePhoneCall({
                        phoneNumber: "10086"
                    })
                } else if (index == 6) {
                    // #ifdef MP
                    this.common()
                    // #endif

                    // #ifndef MP
                    this.onShare()
                    // #endif
                } else {
                    let url = {
                        0: '../message/message',
                        1: "../mall/mall",
                        2: '../my/my',
                        3: '../shopcart/shopcart',
                        5: '/pages/my/feedback/feedback?page=mall'
                    }[index];
                    url && this.f.nav(url)
                }
            },
            // submit() {
            //     this.popupShow = false;
            //     uni.navigateTo({
            //         url: '../submitOrder/submitOrder'
            //     });
            // },
            coupon() {
                uni.navigateTo({
                    url: '../coupon/coupon'
                });
            },
            onShare() {
                // #ifdef MP-WEIXIN
                // 微信小程序中，使用 open-type="share" 的按钮会自动触发 onShareAppMessage
                // 这里可以显示提示信息
                uni.showToast({
                    title: '请点击右上角分享',
                    icon: 'none',
                    duration: 2000
                });
                // #endif
                
                // #ifdef APP-PLUS
                // APP 平台使用原生分享
                plus.share.sendWithSystem({
                    content: (this.proDetail && this.proDetail.name) || '商品详情',
                    href: `https://your-domain.com/subPackage2/productDetail/productDetail?id=${this.id}`
                }, function() {
                    console.log('分享成功');
                }, function(err) {
                    console.log('分享失败：' + JSON.stringify(err));
                    uni.showToast({
                        title: '分享失败',
                        icon: 'none'
                    });
                });
                // #endif
                
                // #ifdef H5
                // H5 平台分享
                if (navigator.share) {
                    navigator.share({
                        title: (this.proDetail && this.proDetail.name) || '商品详情',
                        text: (this.proDetail && this.proDetail.introduction) || '',
                        url: window.location.href
                    }).then(() => {
                        console.log('分享成功');
                    }).catch((err) => {
                        console.log('分享失败', err);
                    });
                } else {
                    // 如果不支持原生分享，复制链接
                    const url = window.location.href;
                    if (navigator.clipboard) {
                        navigator.clipboard.writeText(url).then(() => {
                            uni.showToast({
                                title: '链接已复制',
                                icon: 'success'
                            });
                        });
                    } else {
                        uni.showToast({
                            title: '请手动复制链接',
                            icon: 'none'
                        });
                    }
                }
                // #endif
            },
            shop() {
                this.f.nav('../villageSupport/villageSupport')
            },
            play() {
                uni.navigateTo({
                    url: '../video/video',
                    animationType: 'zoom-out'
                })
            },
            // 联系客服
            contactService() {
                // 组装首条消息，带上商品信息
                const productName = this.proDetail ? this.proDetail.name : '';
                const productId = this.id || '';
                const preset = encodeURIComponent(
                    `商品咨询：商品名称${productName}，商品ID${productId}`
                );
                const avatar = encodeURIComponent('/static/img/tabs/my.png');
                const userName = encodeURIComponent('客服');
                
                // 跳转到聊天页面，并携带预置消息
                uni.navigateTo({
                    url: `/subPackage2/chat/chat?preset=${preset}&userName=${userName}&userAvatar=${avatar}&type=product&productId=${productId}`,
                    fail: () => {
                        uni.showToast({
                            title: "聊天功能暂不可用",
                            icon: "none"
                        });
                    }
                });
            }
        },
        onPageScroll(e) {
            let scroll = e.scrollTop <= 0 ? 0 : e.scrollTop;
            let opcity = scroll / this.scrollH;
            if (this.opcity >= 1 && opcity >= 1) {
                return;
            }
            this.opcity = opcity;
            this.iconOpcity = 0.5 * (1 - opcity < 0 ? 0 : 1 - opcity);
        }
    };
</script>

<style>
    page {
        background: linear-gradient(180deg, #f8f9fa 0%, #e9ecef 100%);
    }

    .container {
        padding-bottom: 110rpx;
        min-height: 100vh;
    }

    .tui-header-box {
        width: 100%;
        position: fixed;
        left: 0;
        top: 0;
        z-index: 995;
    }

    .tui-header {
        width: 100%;
        font-size: 18px;
        line-height: 18px;
        font-weight: 500;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .tui-header-icon {
        position: fixed;
        top: 0;
        left: 10px;
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        height: 32px;
        transform: translateZ(0);
        z-index: 9999;
    }

    .tui-header-icon .tui-badge {
        background: #e41f19 !important;
        position: absolute;
        right: -4px;
    }

    .tui-icon-ml {
        margin-left: 20rpx;
    }

    .tui-icon-box {
        position: relative;
        height: 20px !important;
        width: 20px !important;
        padding: 6px !important;

        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .tui-banner-swiper {
        position: relative;
        border-radius: 0 0 32rpx 32rpx;
        overflow: hidden;
        box-shadow: 0 8rpx 40rpx rgba(0, 0, 0, 0.15);
        background: #fff;
    }

    .tui-video__box {
        width: 166rpx;
        height: 60rpx;
        position: absolute;
        left: 50%;
        bottom: 50rpx;
        transform: translateX(-50%);
        z-index: 2;
    }

    .tui-video__box image {
        width: 166rpx;
        height: 60rpx;
    }

    .tui-video__box view {
        width: 100%;
        height: 100%;
        font-size: 24rpx;
        position: absolute;
        left: 0;
        top: 0;
        display: flex;
        align-items: center;
        padding-left: 66rpx;
        box-sizing: border-box;
    }

    .tui-banner-tag {
        position: absolute;
        color: #fff;
        bottom: 30rpx;
        right: 0;
    }

    .tui-slide-image {
        width: 100%;
        display: block;
    }

    /*顶部菜单*/

    .tui-menu-box {
        box-sizing: border-box;
    }

    .tui-menu-header {
        font-size: 34rpx;
        color: #fff;
        height: 32px;
        display: flex;
        align-items: center;
    }

    .tui-menu-itembox {
        color: #fff;
        padding: 40rpx 10rpx 0 10rpx;
        box-sizing: border-box;
        display: flex;
        flex-wrap: wrap;
        font-size: 26rpx;
    }

    .tui-menu-item {
        width: 22%;
        height: 160rpx;
        border-radius: 24rpx;
        display: flex;
        align-items: center;
        flex-direction: column;
        justify-content: center;
        background: rgba(0, 0, 0, 0.4);
        margin-right: 4%;
        margin-bottom: 4%;
    }

    .tui-menu-item:nth-of-type(4n) {
        margin-right: 0;
    }

    .tui-badge-box {
        position: relative;
    }

    .tui-badge-box .tui-badge-class {
        position: absolute;
        top: -8px;
        right: -8px;
    }

    .tui-msg-badge {
        top: -10px;
    }

    .tui-icon-up_box {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .tui-menu-text {
        padding-top: 12rpx;
    }

    .tui-opcity .tui-menu-text,
    .tui-opcity .tui-badge-box {
        opacity: 0.5;
        transition: opacity 0.2s ease-in-out;
    }

    /*顶部菜单*/

    /*内容 部分*/

    .tui-padding {
        padding: 0 30rpx;
        box-sizing: border-box;
    }

    .tui-ml-auto {
        margin-left: auto;
    }

    /* #ifdef H5 */
    .tui-ptop {
        padding-top: 44px;
    }

    /* #endif */

    .tui-size {
        font-size: 24rpx;
        line-height: 24rpx;
    }

    .tui-gray {
        color: #999;
    }

    .tui-icon-red {
        color: #ff201f;
    }

    .tui-border-radius {
        border-bottom-left-radius: 24rpx;
        border-bottom-right-radius: 24rpx;
        overflow: hidden;
        transition: all 0.3s ease;
    }

    .tui-radius-all {
        border-radius: 24rpx;
        transition: all 0.3s ease;
    }
    
    .tui-product-img.tui-radius-all {
        overflow: visible;
        border-radius: 12rpx;
    }

    .tui-mtop {
        margin-top: 30rpx;
    }

    .tui-pro-detail {
        box-sizing: border-box;
        color: #333;
        padding: 0 20rpx;
        width: 100%;
        overflow-x: hidden;
    }

    /* 商品信息卡片 */
    .tui-product-card {
        background: #fff;
        margin: 20rpx;
        border-radius: 16rpx;
        padding: 30rpx;
        box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
        position: relative;
        overflow: hidden;
    }
    
    .tui-product-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 4rpx;
        /* background: linear-gradient(90deg, #ff6b35, #ff201f, #ff6b35); */
    }

    /* 价格区域 */
    .tui-price-section {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 24rpx;
    }
    
    .tui-price-main {
        flex: 1;
    }
    
    .tui-current-price {
        display: flex;
        align-items: baseline;
        margin-bottom: 8rpx;
    }
    
    .tui-price-symbol {
        font-size: 28rpx;
        color: #ff201f;
        font-weight: 600;
    }
    
    .tui-price {
        font-size: 48rpx;
        font-weight: 700;
        color: #ff201f;
        line-height: 1;
    }
    
    .tui-original-price {
        display: flex;
        align-items: baseline;
    }
    
    .tui-original-price-text {
        font-size: 24rpx;
        color: #999;
        text-decoration: line-through;
        margin-left: 8rpx;
    }
    
    .tui-price-actions {
        display: flex;
        flex-direction: column;
        gap: 20rpx;
    }
    
    .tui-collection-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 16rpx;
        border-radius: 12rpx;
        background: #f8f9fa;
        transition: all 0.3s ease;
    }
    
    .tui-collection-btn:active {
        background: #e9ecef;
        transform: scale(0.95);
    }
    
    .tui-collection-text {
        font-size: 22rpx;
        color: #666;
        margin-top: 4rpx;
    }
    
    .tui-collected {
        color: #ff201f;
    }
    
    .tui-share-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 16rpx;
        border-radius: 12rpx;
        background: #f8f9fa;
        border: none;
        transition: all 0.3s ease;
    }
    
    .tui-share-btn:active {
        background: #e9ecef;
        transform: scale(0.95);
    }
    
    .tui-share-text {
        font-size: 22rpx;
        color: #666;
        margin-top: 4rpx;
    }

    .tui-line-through {
        text-decoration: line-through;
    }
    
    /* 商品标题区域 */
    .tui-title-section {
        margin-bottom: 20rpx;
    }
    
    .tui-product-title {
        font-size: 32rpx;
        font-weight: 600;
        color: #333;
        line-height: 1.4;
        margin-bottom: 12rpx;
    }
    
    .tui-product-subtitle {
        font-size: 26rpx;
        color: #666;
        line-height: 1.4;
    }
    
    /* 商品标签 */
    .tui-tags-section {
        display: flex;
        flex-wrap: wrap;
        gap: 12rpx;
        margin-bottom: 20rpx;
    }
    
    .tui-tag {
        padding: 8rpx 16rpx;
        background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
        color: #0369a1;
        font-size: 22rpx;
        border-radius: 20rpx;
        border: 1rpx solid rgba(14, 165, 233, 0.2);
        font-weight: 500;
    }
    
    /* 销量信息 */
    .tui-sales-info {
        display: flex;
        flex-wrap: wrap;
        gap: 24rpx;
        padding: 16rpx 0;
        border-top: 1rpx solid #f0f0f0;
    }
    
    .tui-sales-item {
        display: flex;
        align-items: center;
        font-size: 24rpx;
    }
    
    .tui-sales-label {
        color: #666;
        margin-right: 8rpx;
    }
    
    .tui-sales-value {
        color: #333;
        font-weight: 500;
    }
    
    /* 规格选择卡片 */
    .tui-spec-card {
        background: #fff;
        margin: 20rpx;
        border-radius: 16rpx;
        padding: 30rpx;
        box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
        position: relative;
        overflow: hidden;
    }
    
    .tui-spec-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 4rpx;
        /* background: linear-gradient(90deg, #ff6b35, #ff201f, #ff6b35); */
    }
    
    .tui-spec-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 20rpx 0;
        border-bottom: 1rpx solid #f0f0f0;
    }
    
    .tui-spec-title {
        flex: 1;
        display: flex;
        align-items: center;
    }
    
    .tui-spec-label {
        font-size: 28rpx;
        color: #333;
        font-weight: 600;
        margin-right: 20rpx;
        min-width: 60rpx;
    }
    
    .tui-spec-content {
        flex: 1;
    }
    
    .tui-spec-text {
        font-size: 26rpx;
        color: #666;
    }
    
    .tui-spec-arrow {
        margin-left: 20rpx;
    }
    
    /* 服务保障 */
    .tui-service-guarantee {
        display: flex;
        flex-wrap: wrap;
        gap: 20rpx;
        padding: 20rpx 0 0 0;
    }
    
    .tui-guarantee-item {
        display: flex;
        align-items: center;
        gap: 8rpx;
        padding: 12rpx 20rpx;
        background: linear-gradient(135deg, #f6ffed, #f0f9ff);
        border-radius: 20rpx;
        border: 1rpx solid rgba(82, 196, 26, 0.2);
    }
    
    .tui-guarantee-text {
        font-size: 24rpx;
        color: #52c41a;
        font-weight: 500;
    }

    .tui-collection {
        color: #333;
        display: flex;
        align-items: center;
        flex-direction: column;
        justify-content: center;
        height: 44rpx;
        padding: 20rpx;
        border-radius: 50%;
        background: #f8f9fa;
        transition: all 0.3s ease;
        flex-shrink: 0;
        min-width: 80rpx;
    }
    
    .tui-collection:active {
        background: #e9ecef;
        transform: scale(0.95);
    }

    .tui-scale-collection {
        transform: scale(0.7);
        transform-origin: center 90%;
        line-height: 24rpx;
        font-weight: normal;
        margin-top: 4rpx;
    }

    .tui-pro-titbox {
        font-size: 32rpx;
        font-weight: 500;
        position: relative;
        padding: 0 150rpx 0 30rpx;
        box-sizing: border-box;
        margin-bottom: 20rpx;
    }

    .tui-pro-title {
        padding-top: 20rpx;
        line-height: 1.5;
        color: #2c3e50;
        font-weight: 600;
    }
    
    .tui-pro-intro {
        padding-top: 15rpx;
        font-size: 28rpx;
        line-height: 1.4;
        color: #666;
        font-weight: 400;
    }

    .tui-share-btn {
        display: block;
        background: transparent;
        margin: 0;
        padding: 0;
        border-radius: 0;
        border: 0;
    }

    .tui-share-btn::after {
        border: 0;
    }

    .tui-share-box {
        display: flex;
        align-items: center;
    }

    .tui-share-position {
        position: absolute;
        right: 0;
        top: 30rpx;
    }

    .tui-share-text {
        padding-left: 8rpx;
    }

    .tui-sub-title {
        padding: 20rpx 0;
        line-height: 32rpx;
    }

    .tui-sale-info {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 20rpx 30rpx;
        background: #f8f9fa;
        border-radius: 12rpx;
        margin: 20rpx 0;
    }

    .tui-discount-box {
        background: #fff;
    }

    .tui-list-cell {
        width: 100%;
        position: relative;
        display: flex;
        align-items: center;
        font-size: 26rpx;
        line-height: 26rpx;
        padding: 36rpx 30rpx;
        box-sizing: border-box;
        transition: background-color 0.3s ease;
    }
    
    .tui-list-cell:active {
        background-color: #f8f9fa;
    }

    .tui-right {
        position: absolute;
        right: 30rpx;
        top: 30rpx;
    }

    .tui-top40 {
        top: 40rpx !important;
    }

    .tui-bold {
        font-weight: bold;
    }

    .tui-list-cell::after {
        content: '';
        position: absolute;
        border-bottom: 1rpx solid #eaeef1;
        -webkit-transform: scaleY(0.5);
        transform: scaleY(0.5);
        bottom: 0;
        right: 0;
        left: 126rpx;
    }

    .tui-last::after {
        border-bottom: 0 !important;
    }

    .tui-flex-center {
        display: flex;
        align-items: center;
    }


    .tui-cell-title {
        width: 66rpx;
        padding-right: 30rpx;
        flex-shrink: 0;
    }

    .tui-promotion-box {
        display: flex;
        align-items: center;
        padding: 10rpx 0;
        width: 80%;
    }

    .tui-promotion-box text {
        width: 70%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .tui-basic-info {
        background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
        box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.12);
        border: 1rpx solid rgba(255, 255, 255, 0.8);
        position: relative;
        overflow: hidden;
    }
    
    .tui-basic-info::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 4rpx;
        background: linear-gradient(90deg, #ff6b35, #ff201f, #ff6b35);
    }

    .tui-addr-box {
        width: 76%;
    }

    .tui-addr-item {
        padding: 10rpx;
        line-height: 34rpx;
    }

    .tui-guarantee {
        background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
        display: flex;
        flex-wrap: wrap;
        padding: 30rpx;
        font-size: 24rpx;
        border-radius: 20rpx;
        margin: 20rpx 0;
        border: 1rpx solid rgba(14, 165, 233, 0.1);
        position: relative;
        overflow: hidden;
    }
    
    .tui-guarantee::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 3rpx;
        background: linear-gradient(90deg, #0ea5e9, #3b82f6, #0ea5e9);
    }

    .tui-guarantee-item {
        color: #0369a1;
        padding: 12rpx 24rpx;
        background: rgba(255, 255, 255, 0.9);
        border-radius: 25rpx;
        margin: 8rpx;
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 10rpx;
        box-shadow: 0 2rpx 8rpx rgba(14, 165, 233, 0.1);
        transition: all 0.3s ease;
        border: 1rpx solid rgba(14, 165, 233, 0.2);
    }
    
    .tui-guarantee-item:hover {
        transform: translateY(-2rpx);
        box-shadow: 0 4rpx 12rpx rgba(14, 165, 233, 0.2);
    }

    .tui-pl {
        padding-left: 4rpx;
    }

    .tui-selected-box {
        color: #999;
        font-size: 26rpx;
        line-height: 26rpx;
        padding: 10rpx 20rpx;
        background: #f8f9fa;
        border-radius: 8rpx;
        border: 1rpx solid #e9ecef;
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-left: 20rpx;
    }

    .tui-cmt-box {
        background: #fff;
    }

    .tui-between {
        justify-content: space-between !important;
    }

    .tui-cmt-all {
        color: #ff201f;
        padding-right: 8rpx;
    }

    .tui-cmt-content {
        font-size: 26rpx;
    }

    .tui-cmt-user {
        display: flex;
        align-items: center;
    }

    .tui-acatar {
        width: 60rpx;
        height: 60rpx;
        border-radius: 30rpx;
        display: block;
        margin-right: 16rpx;
    }

    .tui-cmt {
        padding: 14rpx 0;
    }

    .tui-attr {
        font-size: 24rpx;
        color: #999;
        padding: 6rpx 0;
    }

    .tui-cmt-btn {
        padding: 50rpx 0 30rpx 0;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* 商品详情标题区域 */
    .tui-detail-header {
        margin: 40rpx 0 20rpx 0;
        position: relative;
    }
    
    .tui-detail-title {
        display: flex;
        align-items: center;
        margin-bottom: 20rpx;
    }
    
    .tui-detail-icon {
        width: 40rpx;
        height: 40rpx;
        background: linear-gradient(135deg, #ff6b35, #ff201f);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 15rpx;
    }
    
    .tui-detail-text {
        font-size: 32rpx;
        font-weight: 600;
        color: #2c3e50;
    }
    
    .tui-detail-line {
        height: 4rpx;
        background: linear-gradient(90deg, #ff6b35, #ff201f, transparent);
        border-radius: 2rpx;
    }
    
    /* 商品详情内容区域 */
    .tui-product-detail-content {
        background: #fff;
        border-radius: 20rpx;
        box-shadow: 0 4rpx 30rpx rgba(0, 0, 0, 0.08);
        margin: 20rpx 0;
        overflow: hidden;
        position: relative;
    }
    
    .tui-detail-wrapper {
        padding: 40rpx 30rpx;
        line-height: 1.8;
        color: #333;
    }
    
    /* 商品详情内容样式 */
    .tui-detail-wrapper h1,
    .tui-detail-wrapper h2,
    .tui-detail-wrapper h3,
    .tui-detail-wrapper h4,
    .tui-detail-wrapper h5,
    .tui-detail-wrapper h6 {
        margin: 30rpx 0 15rpx 0;
        font-weight: 600;
        color: #2c3e50;
        position: relative;
        padding-left: 20rpx;
    }
    
    .tui-detail-wrapper h1::before,
    .tui-detail-wrapper h2::before,
    .tui-detail-wrapper h3::before {
        content: '';
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 6rpx;
        height: 24rpx;
        /* background: linear-gradient(135deg, #ff6b35, #ff201f); */
        border-radius: 3rpx;
    }
    
    .tui-detail-wrapper p {
        margin: 15rpx 0;
        line-height: 1.8;
        color: #666;
        font-size: 28rpx;
    }
    
    .tui-detail-wrapper img {
        max-width: 100%;
        height: auto;
        display: block;
        border-radius: 12rpx;
        margin: 20rpx 0;
        box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
        transition: transform 0.3s ease;
    }
    
    .tui-detail-wrapper img:active {
        transform: scale(0.98);
    }
    
    .tui-detail-wrapper ul,
    .tui-detail-wrapper ol {
        margin: 15rpx 0;
        padding-left: 30rpx;
    }
    
    .tui-detail-wrapper li {
        margin: 8rpx 0;
        line-height: 1.6;
        color: #666;
    }
    
    .tui-detail-wrapper table {
        width: 100%;
        border-collapse: collapse;
        margin: 20rpx 0;
        border-radius: 12rpx;
        overflow: hidden;
        box-shadow: 0 2rpx 15rpx rgba(0, 0, 0, 0.05);
    }
    
    .tui-detail-wrapper table th {
        background: linear-gradient(135deg, #f8f9fa, #e9ecef);
        padding: 20rpx 15rpx;
        text-align: left;
        font-weight: 600;
        color: #2c3e50;
        border-bottom: 2rpx solid #ff6b35;
    }
    
    .tui-detail-wrapper table td {
        padding: 15rpx;
        border-bottom: 1rpx solid #f0f0f0;
        color: #666;
    }
    
    .tui-detail-wrapper table tr:last-child td {
        border-bottom: none;
    }
    
    /* 底部提示区域 */
    .tui-detail-footer {
        margin: 30rpx 0;
        display: flex;
        justify-content: center;
    }
    
    .tui-footer-content {
        display: flex;
        align-items: center;
        padding: 15rpx 30rpx;
        background: linear-gradient(135deg, #f6ffed, #f0f9ff);
        border-radius: 25rpx;
        border: 1rpx solid #b7eb8f;
    }
    
    .tui-footer-text {
        margin-left: 10rpx;
        font-size: 24rpx;
        color: #52c41a;
        font-weight: 500;
    }

    /*底部操作栏*/

    .tui-col-7 {
        width: 58.33333333%;
    }

    .tui-col-5 {
        width: 41.66666667%;
    }

    /* 底部操作栏 */
    .tui-bottom-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        display: flex;
        align-items: center;
        padding: 16rpx 20rpx;
        padding-bottom: calc(16rpx + env(safe-area-inset-bottom));
        box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
        z-index: 1000;
        border-top: 1rpx solid #f0f0f0;
    }
    
    .tui-bottom-actions {
        display: flex;
        align-items: center;
        gap: 40rpx;
        margin-right: 20rpx;
    }
    
    .tui-action-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4rpx;
        padding: 8rpx;
        transition: all 0.3s ease;
    }
    
    .tui-action-item:active {
        transform: scale(0.95);
    }
    
    .tui-cart-icon {
        position: relative;
    }
    
    .tui-action-text {
        font-size: 20rpx;
        color: #666;
    }
    
    .tui-collected {
        color: #ff201f;
    }
    
    .tui-bottom-buttons {
        flex: 1;
        display: flex;
        gap: 16rpx;
    }
    
    .tui-btn-container {
        flex: 1;
    }
    
    .tui-cart-btn {
        width: 100%;
        background: linear-gradient(135deg, #ff6b35, #ff201f);
        border: none;
        box-shadow: 0 4rpx 16rpx rgba(255, 107, 53, 0.3);
    }
    
    .tui-buy-btn {
        width: 100%;
        background: linear-gradient(135deg, #ffa726, #ff9800);
        border: none;
        box-shadow: 0 4rpx 16rpx rgba(255, 167, 38, 0.3);
    }

    .tui-safearea-bottom {
        width: 100%;
        height: env(safe-area-inset-bottom);
    }

    .tui-operation::before {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        left: 0;
        border-top: 1rpx solid #eaeef1;
        -webkit-transform: scaleY(0.5);
        transform: scaleY(0.5);
    }

    .tui-operation-left {
        display: flex;
        align-items: center;
    }

    .tui-operation-item {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        position: relative;
        padding: 15rpx;
        border-radius: 16rpx;
        transition: all 0.3s ease;
        background: rgba(255, 255, 255, 0.5);
        margin: 0 8rpx;
        border: 1rpx solid rgba(0, 0, 0, 0.05);
    }
    
    .tui-operation-item:active {
        background: linear-gradient(135deg, #f8f9fa, #e9ecef);
        transform: scale(0.95);
        box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
    }

    .tui-operation-text {
        font-size: 22rpx;
        color: #333;
    }

    .tui-opacity {
        opacity: 0.5;
    }

    .tui-scale-small {
        transform: scale(0.9);
        transform-origin: center center;
    }

    .tui-operation-right {
        height: 100rpx;
        padding: 0 12rpx;
        box-sizing: border-box;
    }

    .tui-right-flex {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .tui-flex-1 {
        flex: 1;
        padding: 8rpx;
        transition: all 0.3s ease;
        margin: 0 6rpx;
    }
    
    .tui-flex-1:active {
        transform: scale(0.98);
    }

    /*底部操作栏*/

    /*底部选择弹层*/

    .tui-popup-class {
        border-top-left-radius: 24rpx;
        border-top-right-radius: 24rpx;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .tui-popup-box {
        position: relative;
        padding: 30rpx 0 100rpx 0;
        background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
        border-radius: 24rpx 24rpx 0 0;
        overflow: hidden;
    }
    
    .tui-popup-box::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 4rpx;
        /* background: linear-gradient(90deg, #ff6b35, #ff201f, #ff6b35); */
    }

    .tui-popup-btn {
        width: 100%;
        position: absolute;
        left: 0;
        bottom: 0;
    }

    /* .tui-popup-btn .tui-btn-class {
		width: 90% !important;
		display: block !important;
		font-size: 28rpx !important;
	} */

    /* .tui-icon-close {
		position: absolute;
		top: 30rpx;
		right: 30rpx;
	} */

    .tui-product-box {
        display: flex;
        align-items: flex-end;
        font-size: 24rpx;
        padding-bottom: 30rpx;
    }

    .tui-popup-img {
        height: 200rpx;
        width: 200rpx;
        border-radius: 24rpx;
        display: block;
    }

    .tui-popup-price {
        padding-left: 20rpx;
        padding-bottom: 8rpx;
    }
    
    .tui-popup-price-main {
        display: flex;
        align-items: baseline;
        gap: 15rpx;
    }
    
    .tui-original-amount {
        font-size: 24rpx;
        color: #999;
        text-decoration: line-through;
    }

    .tui-amount {
        color: #ff201f;
        font-size: 36rpx;
    }

    .tui-number {
        font-size: 24rpx;
        line-height: 24rpx;
        padding-top: 12rpx;
        color: #999;
    }

    .tui-popup-scroll {
        height: 600rpx;
        font-size: 26rpx;
    }

    .tui-scrollview-box {
        padding: 0 30rpx 60rpx 30rpx;
        box-sizing: border-box;
    }

    .tui-attr-title {
        padding: 10rpx 0;
        color: #333;
    }

    .tui-attr-box {
        font-size: 0;
        padding: 20rpx 0;
    }

    .tui-attr-item {
        max-width: 100%;
        min-width: 200rpx;
        height: 64rpx;
        display: -webkit-inline-flex;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, #f8f9fa, #e9ecef);
        padding: 0 26rpx;
        box-sizing: border-box;
        border-radius: 32rpx;
        margin-right: 20rpx;
        margin-bottom: 20rpx;
        font-size: 26rpx;
        transition: all 0.3s ease;
        border: 1rpx solid rgba(0, 0, 0, 0.05);
        box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
    }
    
    .tui-attr-item:active {
        transform: scale(0.98);
    }

    .tui-attr-active {
        /* background: linear-gradient(135deg, #fcedea, #ffe4e1) !important; */
        color: #e41f19;
        font-weight: bold;
        position: relative;
        /* border: 2rpx solid #ff6b35 !important; */
        box-shadow: 0 4rpx 16rpx rgba(255, 107, 53, 0.3) !important;
    }

    .tui-attr-active::after {
        content: '';
        position: absolute;
        border: 2rpx solid #ff6b35;
        width: 100%;
        height: 100%;
        border-radius: 40rpx;
        left: 0;
        top: 0;
        box-shadow: inset 0 0 0 1rpx rgba(255, 107, 53, 0.2);
    }

    .tui-number-box {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 20rpx 0 30rpx 0;
        box-sizing: border-box;
    }

    /*底部选择弹层*/
</style>